import type { Ref } from 'vue';

import type { Dict } from '@croco/framework/types';
import type { AxiosMethod, HttpResponse } from '@croco/plugins/axios';

export interface DataFormProps {
    api?: string;
    method?: AxiosMethod;
    fields?: Array<DataFormItemProps>;
    title?: string;
    rules?: Record<string, any[]>;
    enums?: Record<string, Array<Dict>>;
    width?: number | string;
    footer?: boolean;
    fullscreen?: boolean;
    beforeSubmit?: (data: Ref<Record<string, any>>) => boolean | undefined;
}

export interface DataFormOptionsProps<T = Record<string, any>> {
    data?: T;
    headers?: Record<string, any>;
    success?: (data: HttpResponse) => void;
    failure?: (data: HttpResponse) => void;
    before?: (data: T) => Promise<boolean> | undefined;
}

export interface DataFormItemProps extends Record<string, any> {
    prop: string;
    label?: string;
    primary?: boolean;
    /**
     * 默认值
     */
    value?: any;
    /**
     * 是否禁用
     */
    disabled?: boolean;
    /**
     * 日期格式，同依据该值判断是否使用日期时间选择器
     */
    format?: string;
    /**
     * 单/多选
     */
    multiple?: boolean;
    /**
     * 是否使用插槽，
     * - string：插槽名称，
     * - boolean：连续多个插槽时，第一个插槽需要定义插槽名称，之后的插槽定义为true，则多个插槽共用一个插槽名称
     */
    slot?: boolean | string;
    /**
     * 属性
     */
    attrs?: Record<string, any>;
    /**
     * 提示
     */
    tooltip?: string;
}

export interface DataFormSchema extends Record<string, any> {
    fields?: Array<DataFormItemProps>;
    rules?: Record<string, any>;
}
